﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace _03CreateGeomagic_Arc
{
    public class ArcExam
    {
        [CommandMethod("ArcExam")]
        public void arcDemo()
        {
            // 默认构造函数
            Arc arc1 = new Arc();
            arc1.Center = new Point3d(0, 0, 0);
            arc1.StartAngle = -Math.PI/4;
            arc1.EndAngle = Math.PI / 4;
            arc1.Radius = 100;

            // 圆心 半径 起始角度
            Arc arc2 = new Arc(new Point3d(50, 50, 0), 15, 45, 90);

            Arc arc3 = new Arc(new Point3d(100, 100, 0), new Vector3d(0.0, 0.0, 1.0),20, Math.PI / 4, Math.PI / 2);

            // 加载图形数据库
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                // 打开块表
                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, 
                    OpenMode.ForRead);
                // 打开块表记录
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite);
                // 添加圆弧对象到块表记录
                btr.AppendEntity(arc1);
                // 更新数据
                trans.AddNewlyCreatedDBObject(arc1, true);
                // 事务提交
                trans.Commit();

            }


        }
    }
}
